﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using Manager;
namespace HealthSystem.ReportPage
{
    /// <summary>
    /// Summary description for ChartHandler
    /// </summary>
    public class ChartHandler : IHttpHandler
    {
        JavaScriptSerializer jser = new JavaScriptSerializer();
        ResultManager manager = new ResultManager();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string sactioin = context.Request["saction"];
            if(sactioin=="sumchar")
            {
                chart c = new chart();
                chardata cd = new chardata();
                syear s = new syear();
                c.series = new List<chardata>();

                List<string> categories = new List<string>();
                List<int>datas=new List<int> ();

                var ds = manager.GetCountYearResult();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    categories.Add(ds.Tables[0].Rows[i]["syear"].ToString());
                    datas.Add(Convert.ToInt32(ds.Tables[0].Rows[i]["scount"].ToString()));
                }
                cd.name = "历年学生统计";
                cd.data = datas;
                s.categories = categories;

                c.series.Add(cd);
                c.categories = s;
                context.Response.Write(jser.Serialize(c));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
    public class chart
    {
        public syear categories { get; set; }
        public List<chardata> series{get;set;}
    }
    public class chardata
    {
        public string name{get;set;}
        public List<int> data{get;set;}
    }
    public class syear
    {
        public List<string> categories { get; set; }
    }
}